﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Entities;
using Utility;
using BUS;

public partial class Administrator_sanpham_tinhtrang : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            load_data();
        }
    }

    private void load_data()
    {
        pager.PageSize = 15;
        Criteria c = new Criteria();
        string tinhtrang = "";
        if (Request.QueryString["tinhtrang"] == "close")
        {
            tinhtrang = "Close";
            Literal1.Text = "Danh sách sản phẩm chưa bán ";
        }
        if (Request.QueryString["tinhtrang"] == "open")
        {
            tinhtrang = "Open";
            Literal1.Text = "Danh sách sản phẩm đang bán ";
        }
        if (Request.QueryString["tinhtrang"] == "chayhang")
        {
            tinhtrang = "Cháy Hàng";
            Literal1.Text = "Danh sách sản phẩm cháy hàng ";
        }
        if (Request.QueryString["tinhtrang"] == "outofdate")
        {
            tinhtrang = "Hết Hạn";
            Literal1.Text = "Danh sách sản phẩm hết hạn ";
        }
        if (Request.QueryString["tinhtrang"] == "cancel")
        {
            tinhtrang = "Cancel";
            Literal1.Text = "Danh sách sản phẩm đã bị hủy ";
        }
        c.add(Condition.AND, Tbl_sanpham_Columns.TinhTrang, Condition.LIKE,
                tinhtrang);
        if (txt_tensp.Text != "")
        {
            c.add(Condition.AND, Tbl_sanpham_Columns.TenSP, Condition.LIKE,
                txt_tensp.Text);
        }

        int total = 0;
        Tbl_sanpham_Collection spCollection =
           Tbl_sanpham_BUS.Get(c.Criter, pager.CurrentIndex, pager.PageSize,
            Tbl_sanpham_Columns.STT.ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater1.DataSource = spCollection;
        Repeater1.DataBind();

        pager.ItemCount = total;

    }

    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
                  e.Item.ItemType == ListItemType.Item)
        {
            Tbl_sanpham_Entities sp = (Tbl_sanpham_Entities)e.Item.DataItem;
            Literal lit_stt = (Literal)e.Item.FindControl("lit_stt");
            Literal lit_masp = (Literal)e.Item.FindControl("lit_masp");
            HyperLink hyp_tensp = (HyperLink)e.Item.FindControl("hyp_tensp");
            Literal lit_giaban = (Literal)e.Item.FindControl("lit_giaban");
            Literal lit_tinhtrang = (Literal)e.Item.FindControl("lit_tinhtrang");

            lit_stt.Text = sp.STT.ToString();
            lit_masp.Text = sp.MaSP.ToString();
            hyp_tensp.NavigateUrl = "";
            lit_giaban.Text = sp.GiaBan.ToString();
            lit_tinhtrang.Text = sp.TinhTrang;
            hyp_tensp.NavigateUrl = "~/Administrator/sanpham_chitiet.aspx?id=" + sp.STT.ToString();
            HyperLink hpl_sua = (HyperLink)e.Item.FindControl("hpl_sua");
            hpl_sua.ImageUrl = "~/GiaoDien/images/modify_icon.jpg";
            hpl_sua.NavigateUrl = "~/Administrator/sanpham_modify.aspx?id=" + sp.STT.ToString();

            HyperLink hpl_xoa = (HyperLink)e.Item.FindControl("hpl_xoa");
            hpl_xoa.ImageUrl = "~/GiaoDien/images/del_icon.jpg";
            hpl_xoa.NavigateUrl = "~/Administrator/delete.aspx?idsanpham=" + sp.STT.ToString();

        }
    }
    protected void bt_timkiem_Click(object sender, EventArgs e)
    {
        load_data();
    }
}
